#!/usr/bin/python
# -*- coding: UTF-8 -*-
__author__ = 'dengqianyi'
import sys
import os
sys.path.append("..")
from common.xlsComponent import XlsComponent
from common.myFileSearch import MySearch_file
import mainHelp
import xlsReloadHelp

_shenguo = "神国".decode('utf-8')
_chaoshen = "超神".decode('utf-8')
_shangshen = "上神".decode('utf-8')
_zhongshen = "中神".decode('utf-8')
_xiashen = "下神".decode('utf-8')
_lieshen = "劣神".decode('utf-8')
_shangjin = "上金".decode('utf-8')
_zhongjin = "中金".decode('utf-8')
_xiajin = "下金".decode('utf-8')
_yin = "银".decode("utf-8")
_tong = "铜".decode("utf-8")

_baimingdan = "白名单".decode('UTF-8')
_yuanfenguihua = "缘分规划".decode("UTF-8")
_qunti = "群体".decode("UTF-8")
_qunti1 = "群体1".decode("UTF-8")
_qunti2 = "群体2".decode("UTF-8")
_shengchengyuanfen = "生成缘分".decode("UTF-8")
_shengchengchufaji = "生成触发集".decode("UTF-8")
_wujiang = "武将".decode("UTF-8")
_mingcheng = "名称".decode("UTF-8")
_wuqi = "武器".decode("UTF-8")
_zuoqi="坐骑".decode("utf-8")
_zhi = "智".decode('utf-8')
_fang = "防".decode('utf-8')
_xue = "血".decode('utf-8')
_zhuangbei = "装备".decode('utf-8')
_jineng = "技能".decode('utf-8')
_fangju="防具".decode('utf-8')
_jinnang = "锦囊".decode('utf-8')
_danren = "单人".decode('utf-8')
_shuxing="属性".decode('utf-8')
_id = "id".decode("UTF-8")
_peiqi = "配齐".decode("utf-8")
_putong = "普通".decode("utf-8")
#生成缘分表
_yuanfenId = "缘分id".decode("UTF-8")
_yuanfenwujiang = "缘分武将".decode("UTF-8")
_yuanfenpinzhi = "缘分品质".decode("UTF-8")
_pinzhi = "品质".decode('utf-8')
_yuanfentiaojian="缘分条件".decode("UTF-8")
_yuanfenleixing="缘分类型".decode("utf-8")
_quntiyuanming="群体缘名".decode("utf-8")
_yuanfenmingzi="缘分名字".decode("utf-8")
_yuanfenxiangxileixing = "缘分详细类型".decode('utf-8')
_yuanfenjiacheng="缘分加成".decode('utf-8')
_yuanfenxiaoguostep="效果step".decode('utf-8')
_yuanfenxiaoguo="缘分效果".decode("utf-8")
_yuanfenxiaoguo1="缘分效果1".decode("utf-8")
_danren1="单人1".decode("utf-8")
_danren2="单人2".decode("utf-8")
_danren3="单人3".decode("utf-8")
_shuxing1="属性1".decode("utf-8")
_shuxing2="属性2".decode("utf-8")
_shuxing3="属性3".decode("utf-8")
_zhuangbeiqunti="装备群体".decode("utf-8")
_zhushenzhiguo="诸神之国".decode("utf-8")
_zhushenguo="诸神国".decode('utf-8')
#程序辅助
_chengxufuzhu="程序辅助".decode('utf-8')
#触发集
_wujiangmingcheng = "武将名称".decode("utf-8")
# 修正
_xiuzheng = "修正".decode("utf-8")
_xiuzheng1 = "修正1".decode("utf-8")
_yuanfenmingzi1 = "缘分名字1".decode("utf-8")
_xiuzheng2 = "修正2".decode("utf-8")
_yuanfenmingzi2 = "缘分名字2".decode("utf-8")
_xiuzheng3 = "修正3".decode("utf-8")
_yuanfenmingzi3 = "缘分名字3".decode("utf-8")
_xiuzheng4 = "修正4".decode("utf-8")
_yuanfenmingzi4 = "缘分名字4".decode("utf-8")
_xiuzheng5 = "修正5".decode("utf-8")
_yuanfenmingzi5 = "缘分名字5".decode("utf-8")
_xiuzheng6 = "修正6".decode("utf-8")
_yuanfenmingzi6 = "缘分名字6".decode("utf-8")


class _FateId(object):
    _FateIDDict = dict()
    def __init__(self):
        #存放相关的武将id，判断当前fateid应该为多少
        self._generateId = ""
        self._idnum = 0
    def getFateId(self,generateId):
        #获得后self._idnum + 1
        # print "_FateId generateId",generateId
        if _FateId._FateIDDict.get(generateId) == None:
            _FateId._FateIDDict[generateId] = 1
        self._idnum = _FateId._FateIDDict[generateId]
        if self._idnum < 10:
            _resultId = "4"+generateId[1:]+"0"+str(self._idnum)
        else:
            _resultId = "4"+generateId[1:]+str(self._idnum)
        _FateId._FateIDDict[generateId] = self._idnum + 1
        # print _resultId
        return _resultId
    @classmethod
    def clear(cls):
        _FateId._FateIDDict=dict()

class FateGenerate(object):
    def __init__(self,xlsPathName,xlsOutputPathName):
        self._xlsComponent = XlsComponent(xlsPathName)
        self._xlsCodeComponent = XlsComponent(xlsOutputPathName,isOutFileFlag=True)
        # 缘分规划
        self.contentList_yuanfenguihua = self._xlsComponent.getXlsContentDict().get(_yuanfenguihua)
        self.titleList_yuanfenguihua = self._xlsComponent.getTitleDict().get(_yuanfenguihua)

        #白名单
        self.contentList_baimingdan = self._xlsComponent.getXlsContentDict().get(_baimingdan)
        self.titleList_baimingdan = self._xlsComponent.getTitleDict().get(_baimingdan)

        #生成缘分
        self.contentList_shengchengyuanfen = self._xlsCodeComponent.getXlsContentDict().get(_shengchengyuanfen)
        self.titleList_shengchengyuanfen = self._xlsCodeComponent.getTitleDict().get(_shengchengyuanfen)
        #生成触发集
        self.contentList_shengchengchufaji = self._xlsCodeComponent.getXlsContentDict().get(_shengchengchufaji)
        self.titleList_shengchengchufaji = self._xlsCodeComponent.getTitleDict().get(_shengchengchufaji)

        #群体
        self.contentList_qunti = self._xlsComponent.getXlsContentDict().get(_qunti)
        self.titleList_qunti = self._xlsComponent.getTitleDict().get(_qunti)


        #关注相应的消息
        mainHelp.Connection.addEvents("onReceiveMessage",self.onReceiveMessage)
        #把相应的xls添加到监控
        xlsReloadHelp.getInstance().addXlsToMonitor(xlsPathName)
        pass
    def _getQualityName(self,pinzhi):
        if pinzhi == _shenguo:
            return "神".decode('utf-8')
        if pinzhi == _chaoshen:
            return "神".decode('utf-8')
        if pinzhi == _shangshen:
            return "神".decode('utf-8')
        if pinzhi == _zhongshen:
            return "神".decode('utf-8')
        if pinzhi == _xiashen:
            return "神".decode('utf-8')
        if pinzhi == _lieshen:
            return "神".decode('utf-8')
        if pinzhi == _shangjin:
            return "金".decode('utf-8')
        if pinzhi == _zhongjin:
            return "金".decode('utf-8')
        if pinzhi == _xiajin:
            return "金".decode('utf-8')
        if pinzhi == _yin:
            return "银".decode('utf-8')
        if pinzhi == _tong:
            return "铜".decode('utf-8')
    def onReceiveMessage(self,jsonObj):
        if jsonObj.get("msgType") != "FateGenerate":
            return
        print "FateGenerate onReceiveMessage",jsonObj
        self.msgHandler(jsonObj)
        pass
    def msgHandler(self,jsonObj):
        if jsonObj.get("msgFunc") == "shengchengyuanfen":
            self.shengchengyuanfen(jsonObj)
            return
        if jsonObj.get("msgFunc") == "shengchengchufaji":
            print "msgHandler shengchengchufaji"
            self.shengchengchufaji(jsonObj)
            return
        if jsonObj.get("msgFunc") == "shengchengxml":
            self.shengchengXML(jsonObj)
            return
        pass
    def shengchengXML(self,jsonObj):
        _shengchengyuanfenContentDict = self._xlsCodeComponent.getXlsContentDict().get(_shengchengyuanfen)
        _shengchengyuanfenXMLPath = os.path.join(os.path.split(self._xlsCodeComponent.getXlsPathDir())[0],'shengchengyuanfen.xml')
        print _shengchengyuanfenXMLPath
        self._xlsCodeComponent.saveContentToXmlFile(_shengchengyuanfenContentDict,_shengchengyuanfenXMLPath,"yuanfen")

        _shengchengyuanfenContentDict = self._xlsCodeComponent.getXlsContentDict().get(_shengchengchufaji)
        _shengchengyuanfenXMLPath = os.path.join(os.path.split(self._xlsCodeComponent.getXlsPathDir())[0],'shengchengchufaji.xml')
        print _shengchengyuanfenXMLPath
        self._xlsCodeComponent.saveContentToXmlFile(_shengchengyuanfenContentDict,_shengchengyuanfenXMLPath,"chufaji")
        pass
    def shengchengchufaji(self,jsonObj):
        #清空
        del self.contentList_shengchengchufaji[:]
        #根据“白名单”,“生成缘分”生成“生成触发集”表
        for _index in range(0,len(self.contentList_baimingdan)):
            _baimingdan_contentDict = self.contentList_baimingdan[_index]
            _generateName = _baimingdan_contentDict.get(_mingcheng)
            if _generateName != None:
                for _index in xrange(0,len(self.contentList_shengchengyuanfen)):
                    _contentDict = self.contentList_shengchengyuanfen[_index]
                    # print "shengchengchufaji",_generateName,_contentDict.get(_yuanfenwujiang)
                    if _generateName == _contentDict.get(_yuanfenwujiang) or _generateName == _contentDict.get(_yuanfenwujiang+"flag"):
                        # print _generateName
                        # print _contentDict.get(_yuanfenwujiang)
                        print "test",_contentDict.get(_yuanfenwujiang+"flag")
                        if _contentDict.get(_yuanfenxiangxileixing) != _qunti:
                            _lineContentDict = dict()
                            _lineContentDict[_id] = _contentDict.get(_yuanfenId)
                            _lineContentDict["type"] = _contentDict.get(_yuanfenleixing)
                            _lineContentDict["name"] = _contentDict.get(_chengxufuzhu)
                            _lineContentDict["generalName"] = _generateName
                            self.contentList_shengchengchufaji.append(_lineContentDict)
                        elif _contentDict.get(_yuanfenxiangxileixing) == _qunti:
                            #群体,需要全部解析出来
                            _quntiName = _contentDict.get(_chengxufuzhu)
                            #遍历群体表
                            for _indexQunti in xrange(0,len(self.contentList_qunti)):
                                _quntiLineContent = self.contentList_qunti[_indexQunti]
                                # print _quntiLineContent.get(_quntiyuanming),_quntiName,_quntiLineContent.get(_quntiyuanming) == _quntiName
                                if _quntiLineContent.get(_quntiyuanming) == _quntiName:
                                    _lineContentDict = dict()
                                    _lineContentDict[_id] = _contentDict.get(_yuanfenId)
                                    _lineContentDict["type"] = _contentDict.get(_yuanfenleixing)
                                    _lineContentDict["name"] = _quntiLineContent.get(_wujiangmingcheng)
                                    _lineContentDict["generalName"] = _generateName
                                    # print _lineContentDict
                                    self.contentList_shengchengchufaji.append(_lineContentDict)
                    pass
        self._xlsCodeComponent.saveLastContentToXls()
        pass
    def shengchengyuanfen(self,jsonObj):
        # 清空
        del self.contentList_shengchengyuanfen[:]
        #根据“白名单”,“缘分规划”生成“生成缘分”表
        for _index in range(0,len(self.contentList_baimingdan)):
            _baimingdan_contentDict = self.contentList_baimingdan[_index]
            _generateName = _baimingdan_contentDict.get(_mingcheng)
            _rowIndex = 0
            for _index in xrange(0,len(self.contentList_yuanfenguihua)):
                _shuxingNum = 1
                #每行数据
                _contentDict = self.contentList_yuanfenguihua[_index]
                if _generateName != _contentDict.get(_wujiang):
                    continue
                #各种缘分数量
                _yfsl,_qtyfsl,_qtzbyfsl = self.scyf_yfsl_qtyfsl(_contentDict,_rowIndex)
                #武器
                if self.scyf_wuqi(_contentDict.get(_wuqi),_contentDict,_contentDict.get(_shuxing+str(_shuxingNum)),_yfsl,_qtyfsl,_shuxingNum,_rowIndex) == True:
                    _shuxingNum += 1
                #防具
                if self.scyf_fangju(_contentDict.get(_fangju),_contentDict,_contentDict.get(_shuxing+str(_shuxingNum)),_yfsl,_qtyfsl,_shuxingNum,_rowIndex) == True:
                    _shuxingNum += 1
                #锦囊
                if self.scyf_jinnang(_contentDict.get(_jinnang),_contentDict,_contentDict.get(_shuxing+str(_shuxingNum)),_yfsl,_qtyfsl,_shuxingNum,_rowIndex) == True:
                    _shuxingNum += 1
                #坐骑
                if self.scyf_zuoqi(_contentDict.get(_zuoqi),_contentDict,_contentDict.get(_shuxing+str(_shuxingNum)),_yfsl,_qtyfsl,_shuxingNum,_rowIndex) == True:
                    _shuxingNum += 1
                #装备群体
                if self.scyf_zhuangbeiqunti(_contentDict.get(_zhuangbeiqunti),_contentDict,_contentDict.get(_shuxing+str(_shuxingNum)),_shuxingNum,_rowIndex):
                    _shuxingNum += 1
                #技能
                if self.scyf_jineng(_contentDict.get(_jineng),_contentDict,_contentDict.get(_shuxing+str(_shuxingNum)),_yfsl,_qtyfsl,_shuxingNum,_rowIndex) == True:
                    _shuxingNum += 1
                #单人
                for _index in xrange(1,4):
                    _danrenTemp = _danren+str(_index)
                    _shuxingTemp =_shuxing+str(_shuxingNum)
                    if self.scyf_danren(_contentDict.get(_danrenTemp),_contentDict,_contentDict.get(_shuxingTemp),_yfsl,_qtyfsl,_shuxingNum,_rowIndex) == True:
                        _shuxingNum += 1
                #群体1,2
                for _index in xrange(1,3):
                    _quntiTemp = _qunti+str(_index)
                    _shuxingTemp=_shuxing+str(_shuxingNum)
                    if self.scyf_qunti(_contentDict.get(_quntiTemp),_contentDict,_contentDict.get(_shuxingTemp),_shuxingNum,_rowIndex) == True:
                        _shuxingNum += 1
                _rowIndex = _rowIndex+1
        #存储前，需要清空临时值供下次使用
        _FateId.clear()
        self._xlsCodeComponent.saveLastContentToXls()
        pass
    def scyf_yfsl_qtyfsl(self,_contentDict,rowNum):
        #计算缘分数量和群体缘分数量
        _yfsl = 0
        _qtyfsl = 0
        _qtzbyfsl = 0
        for key,value in _contentDict.items():
            if (key == _wuqi and value != None)or\
                (key == _fangju and value != None)or\
                (key == _jinnang and value != None)or\
                (key == _zuoqi and value != None)or\
                (key == _jineng and value != None)or\
                (key == _danren1 and value != None)or\
                (key == _danren2 and value != None)or\
                (key == _danren3 and value != None):
                _yfsl += 1
                pass
            if (key == _zhuangbeiqunti and value != None):
                _yfsl += 1
                _qtzbyfsl += 1
            if (key == _qunti1 and value != None)or\
                (key ==_qunti2 and value != None):
                _yfsl += 1
                _qtyfsl += 1
        # print "scyf_yfsl_qtyfsl",_yfsl,_qtyfsl,_qtzbyfsl
        return _yfsl,_qtyfsl,_qtzbyfsl
        pass
    def scyf_yuanfenxiaoguo(self,pinzhi,yfsl,qtyfsl):
        #yfsl == 缘分数量,qtyfsl == 群体缘分数量，pinzhi == 品质
        def _shangxian(pinzhi):
            if pinzhi == _shenguo:
                return 160
            if pinzhi == _chaoshen:
                return 140
            if pinzhi == _shangshen:
                return 140
            if pinzhi == _zhongshen:
                return 125
            if pinzhi == _xiashen:
                return 100
            if pinzhi == _lieshen:
                return 80
            if pinzhi == _shangjin:
                return 70
            if pinzhi == _zhongjin:
                return 60
            if pinzhi == _xiajin:
                return 50
            if pinzhi == _yin:
                return 30
            if pinzhi == _tong:
                return 12
        _shangxianValue = _shangxian(pinzhi)
        # print "scyf_yuanfenxiaoguo _shangxianValue",_shangxianValue,pinzhi,qtyfsl,yfsl
        _result = int((_shangxianValue - 30*qtyfsl)/(yfsl-qtyfsl))
        # print "scyf_yuanfenxiaoguo _result",_result
        return _result
        pass
    def scyf_wuqi(self,equipName,lineContentDict,shuxing,yfsl,qtyfsl,offset,rowNum):
        #yfsl   单体缘分数量
        if equipName == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _zhuangbei
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_wuqi
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] = self._getQualityName(lineContentDict.get(_pinzhi))
        # print "123",lineContentDict.get(_xiuzheng+str(offset))
        # print "321",self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl)
        _online_scyf[_yuanfenxiaoguo]=int(self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl))+int(lineContentDict.get(_xiuzheng+str(offset)))
        _online_scyf[_chengxufuzhu]=equipName
        # _online_scyf[_yuanfenxiaoguo1]=0

        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
        pass
    def scyf_zuoqi(self,zuoqiName,lineContentDict,shuxing,yfsl,qtyfsl,offset,rowNum):
        if zuoqiName == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _zhuangbei
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_zuoqi
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] = self._getQualityName(lineContentDict.get(_pinzhi))
        _online_scyf[_yuanfenxiaoguo]=int(self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl))+int(lineContentDict.get(_xiuzheng+str(offset)))
        _online_scyf[_chengxufuzhu]=zuoqiName
        # _online_scyf[_yuanfenxiaoguo1]=0
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
        pass
    def scyf_jineng(self,jinengName,lineContentDict,shuxing,yfsl,qtyfsl,offset,rowNum):
        if jinengName == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _jineng
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_jineng
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] = self._getQualityName(lineContentDict.get(_pinzhi))
        _online_scyf[_yuanfenxiaoguo]=int(self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl))+int(lineContentDict.get(_xiuzheng+str(offset)))
        _online_scyf[_chengxufuzhu]=jinengName
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
        pass
    def scyf_fangju(self,name,lineContentDict,shuxing,yfsl,qtyfsl,offset,rowNum):
        if name == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _zhuangbei
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_fangju
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] = self._getQualityName(lineContentDict.get(_pinzhi))
        _online_scyf[_yuanfenxiaoguo]=int(self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl))+int(lineContentDict.get(_xiuzheng+str(offset)))
        _online_scyf[_chengxufuzhu]=name
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
        pass
    def scyf_jinnang(self,name,lineContentDict,shuxing,yfsl,qtyfsl,offset,rowNum):
        if name == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _zhuangbei
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_jinnang
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] = self._getQualityName(lineContentDict.get(_pinzhi))
        _online_scyf[_yuanfenxiaoguo]=int(self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl))+int(lineContentDict.get(_xiuzheng+str(offset)))
        _online_scyf[_chengxufuzhu]=name
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
        pass
    def scyf_danren(self,danrenName,lineContentDict,shuxing,yfsl,qtyfsl,offset,rowNum):
        if danrenName == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _wujiang
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_danren
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] = self._getQualityName(lineContentDict.get(_pinzhi))
        _online_scyf[_yuanfenxiaoguo]=int(self.scyf_yuanfenxiaoguo(lineContentDict.get(_pinzhi),yfsl,qtyfsl))+int(lineContentDict.get(_xiuzheng+str(offset)))
        _online_scyf[_chengxufuzhu]=danrenName
        # _online_scyf[_yuanfenxiaoguo1]=0
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
        pass
    def scyf_qunti(self,name,lineContentDict,shuxing,offset,rowNum):
        if name == None:
            return False
        def _quntiValue(name):
            _count = 0
            for _index in xrange(0,len(self.contentList_qunti)):
                _indexDict = self.contentList_qunti[_index]
                for key,value in _indexDict.items():
                    # print "scyf_qunti _quntiValue",key,name
                    if value == name:
                        _count += 1
            # print "scyf_qunti _quntiValue",_count,name
            if _count == 3:
                return 30
            if _count == 4:
                return 35
            if _count == 5:
                return 45
            pass
            return _count
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _wujiang
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _peiqi
        _online_scyf[_yuanfenxiangxileixing] =_qunti
        # print "scyf_qunti",name,_quntiValue(name)
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=0
        _online_scyf[_yuanfenpinzhi] =self._getQualityName(lineContentDict.get(_pinzhi))
        # print name
        if lineContentDict.get(_xiuzheng+str(offset)) != None:
            _online_scyf[_yuanfenxiaoguo]=_quntiValue(name)+int(lineContentDict.get(_xiuzheng+str(offset)))
        else:
            _online_scyf[_yuanfenxiaoguo]=_quntiValue(name)
        _online_scyf[_chengxufuzhu]=name
        # _online_scyf[_yuanfenxiaoguo1]=0
        if name == _zhushenzhiguo or name == _zhushenguo:
            _online_scyf[_yuanfenxiaoguo]=15
            if name == _zhushenguo:
                #"诸神国"缘分比较特殊
                _online_scyf[_yuanfenxiaoguo] = 0
            _online_scyf[_yuanfenxiaoguostep]=15
            _online_scyf[_yuanfentiaojian]=_putong
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
    def scyf_zhuangbeiqunti(self,name,lineContentDict,shuxing,offset,rowNum):
        if name == None:
            return False
        #缘分表每一行
        _online_scyf = dict()
        #武将名字
        _generateName = lineContentDict.get(_wujiang)
        _online_scyf[_yuanfenId] = self.scyf_getId(_generateName)
        if rowNum == 0:
            _online_scyf[_yuanfenwujiang] = _generateName
        else:
            _online_scyf[_yuanfenwujiang] = None
            #增加一行，标识此行为特殊行
            _online_scyf[_yuanfenwujiang+'flag'] = _generateName
        _online_scyf[_yuanfenpinzhi]=""
        _online_scyf[_yuanfenleixing] = _zhuangbei
        _online_scyf[_yuanfenmingzi] = lineContentDict.get(_yuanfenmingzi+str(offset))
        _online_scyf[_yuanfentiaojian] = _putong
        _online_scyf[_yuanfenxiangxileixing] =_qunti
        _online_scyf[_yuanfenjiacheng]=shuxing
        _online_scyf[_yuanfenxiaoguostep]=5
        _online_scyf[_yuanfenpinzhi] =self._getQualityName(lineContentDict.get(_pinzhi))
        _online_scyf[_yuanfenxiaoguo]=20
        _online_scyf[_chengxufuzhu]=name
        # _online_scyf[_yuanfenxiaoguo1]=0
        self.contentList_shengchengyuanfen.append(_online_scyf)
        return True
    def scyf_getId(self,generateName):
        #根据白名单id，得到缘分id的起始位置
        _resultId = "error"
        for _index in xrange(0,len(self.contentList_baimingdan)):
            _lineDict = self.contentList_baimingdan[_index]
            if _lineDict.get(_mingcheng) == generateName:
                _resultId = _lineDict.get(_id)
                _fateIdObj = _FateId()
                return _fateIdObj.getFateId(_resultId)
                pass
    pass